#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/4/15 15:43
# @Author  : Chenmm
# @File    : SysDict.py
# @Software: PyCharm

from app import db
from datetime import datetime

class SysDict(db.Model):
    __tablename__ = 'sys_dict'

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
    dict_code = db.Column(db.String(50), comment='类型编码')
    name = db.Column(db.String(50), comment='类型名称')
    status = db.Column(db.SmallInteger, default=0, comment='状态')
    remark = db.Column(db.String(255), comment='备注')
    create_time = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
    create_by = db.Column(db.BigInteger, comment='创建人ID')
    update_time = db.Column(db.DateTime, onupdate=datetime.now, comment='更新时间')
    update_by = db.Column(db.BigInteger, comment='修改人ID')
    is_deleted = db.Column(db.SmallInteger, default=0, comment='是否删除')

    __table_args__ = (
        db.Index('idx_dict_code', 'dict_code'),
        {'comment': '字典表'}
    )





class SysDictItem(db.Model):
    __tablename__ = 'sys_dict_item'

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
    dict_code = db.Column(db.String(50), comment='关联字典编码')
    value = db.Column(db.String(50), comment='字典项值')
    label = db.Column(db.String(100), comment='字典项标签')
    tag_type = db.Column(db.String(50), comment='标签类型')
    status = db.Column(db.SmallInteger, default=0, comment='状态')
    sort = db.Column(db.Integer, default=0, comment='排序')
    remark = db.Column(db.String(255), comment='备注')
    create_time = db.Column(db.DateTime, comment='创建时间')
    create_by = db.Column(db.BigInteger, comment='创建人ID')
    update_time = db.Column(db.DateTime, comment='更新时间')
    update_by = db.Column(db.BigInteger, comment='修改人ID')

    __table_args__ = {'comment': '字典项表'}

    def to_option_json(self):
        option = {
            'value': self.value,
            'label': self.label,
            'tag': self.tag_type
        }

        return option



